<template>
	<view class="video-manage">
		<view class="video-manage-list" v-if="videoList.length">
			<view class="video-manage-item" v-for="(data,index) in videoList" :key="index">
				<image :src="data.image" mode="aspectFill"></image>
				<view class="video-manage-item-info">
					<view class="video-manage-item-info-tit">{{data.name}}</view>
					<view class="video-manage-item-info-des">{{data.brief}}</view>
					<view class="video-manage-item-info-action">
						<text @click.stop="add(data.video_id)">修改</text>
						<text @click.stop="del(data.video_id)">删除</text>
					</view>
				</view>
			</view>
			<no-more :text="'数据加载完毕'" v-if="videoList.length && noMore"></no-more>
		</view>
		<nothing style="margin-top: -90rpx;" :text="'还未添加视频'" :btn="false" v-else></nothing>
		<view class="video-manage-btn">
			<view class="video-manage-btn-box" @click="add()">
				<view>上传视频</view>
				<text>(建议20MB以内)</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				videoList: [],
				isRefresh: false,
				page: 0,
				noMore: false
			};
		},
		onShow() {
			this.videoList = []
			this.init(0)
		},
		onReachBottom() {
			if(!this.noMore){
				this.page++
				this.init(this.page)
			}
		},
		methods:{
			init(page){
				let data = {
					limit: 10,
					page: page?page:0,
					order_by: 'add_time',
					user_id: JSON.parse(uni.getStorageSync('userInfo')).user_id,
					store_id: JSON.parse(uni.getStorageSync('userInfo')).store_id,
					status: 1
				}
				this.$api.VideoList(data).then(res => {
					if(res.datas.length){
						res.datas.forEach(item => {
							this.videoList.push(item)
						})
					}else{
						this.noMore = true
					}
				})
			},
			del(id){
				let _this = this
				uni.showModal({
					content: '是否删除此视频？',
					success(res) {
						if(res.confirm){
							_this.$api.OutVideo({video_id: id,status: 2}).then(res => {
								uni.showToast({
									icon: "none",
									title: "删除成功",
									duration: 1500
								})
								setTimeout(() => {
									_this.videoList = []
									_this.init(0)
								},1500)
							})
						}
					}
				})
			},
			add(id){
				if(id){
					uni.navigateTo({
						url: '/pages/video-manage/video-info?id='+id
					})
				}else{
					uni.navigateTo({
						url: '/pages/video-manage/video-info'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	@import '../../static/scss/video.scss'
</style>